﻿
using MediatR;
using SY.BasicData.Api.Read.Applications.Slaughter.Command;
using SY.BasicData.Domain.SlaughterInformation;
using SY.BasicData.ErrorCode;
using SY.BasicData.Infrastructures;

namespace SY.BasicData.Api.Read.Applications.Slaughter.CommandHandler
{
    public class SlaughterQueryCommandHandler : IRequestHandler<SlaughterQueryCommand, ApiResult<SlaughterCommpanyModel>>
    {
        private readonly IBaseRepository<SlaughterCommpanyModel> baseRepository;

        public SlaughterQueryCommandHandler(IBaseRepository<SlaughterCommpanyModel> baseRepository)
        {
            this.baseRepository = baseRepository;
        }

        public Task<ApiResult<SlaughterCommpanyModel>> Handle(SlaughterQueryCommand request, CancellationToken cancellationToken)
        {
            ApiResult<SlaughterCommpanyModel> result=new ApiResult<SlaughterCommpanyModel>();
            result.Code = ApiEnum.Success;
            result.Message = "屠杀企业信息反填成功";
            var list = baseRepository.GetAll().Where(x => x.Batch == request.Batch).FirstOrDefault();
            if (list == null)
            {
                result.Code = ApiEnum.Fail;
                result.Message = "找不到此信息";
                return Task.FromResult(result);
            }
            result.Data = list;
            return Task.FromResult(result);
        }
    }
}
